package com.cloudkinto.cron;

import com.cloudkinto.dao.ShopDao;
import com.cloudkinto.entity.OrderOutputProductDo;
import com.cloudkinto.entity.ShopDo;
import com.cloudkinto.service.order.OrderAmazonVdfService;
import com.cloudkinto.service.order.OrderRakutenService;
import com.cloudkinto.service.order.OrderYahooService;
import com.cloudkinto.service.orderoutput.OrderOutputService;
import com.cloudkinto.service.redpacket.WxRedPacketService;
import com.cloudkinto.service.shipprice.ShipPriceService;
import com.cloudkinto.service.shipprice.impl.ShipPriceServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangyy
 * @date 2020/6/18 16:03
 * @description: 定时任务
 */
@ConditionalOnProperty(prefix = "gbc", name = "scheduling", havingValue = "prod")
@Component
public class CronService {
    @Autowired
    private WxRedPacketService redPacketService;
    @Autowired
    private OrderOutputService outputService;
    @Autowired
    private OrderRakutenService rakutenService;
    @Autowired
    private ShipPriceService mShipPriceService;
    @Autowired
    private OrderAmazonVdfService vdfService;
    @Autowired
    private ShopDao shopDao;
    @Autowired
    private OrderYahooService yahooService;


    @Scheduled(cron = "0 0 23 10 * *")
//    @Scheduled(fixedDelay = 10 * 60 * 1000)
    private void updateWxPayPlatformNo() {
        redPacketService.getWXxPayCertificates();
    }


    // @Scheduled(cron = "0 2/5 * * * ?")
   @Scheduled(fixedDelay = 10 * 60 * 1000)
    private void updateOrderOutChehckStatus() {
        outputService.updateOrderOutCheckStatus();
    }

    @Scheduled(initialDelay = 1000,fixedDelay = 100000 * 60 * 1000)
//    @Scheduled(fixedDelay = 10 * 60 * 1000)
    private void test() {
        ShopDo shopDo = shopDao.selectById(546);
        // vdfService.getCreatLabelsStatus(shopDo, "65e80570-9462-4822-b8cc-223ee627422f-20240905065520");
    }

    @Scheduled(cron = "0 30 0/1 * * ?")
    private void autoSendRakutenOrder() {
        rakutenService.autoSendRakutenOrder();
    }
    @Scheduled(cron = "0 0/20 * * * ?")
    private void autoSendRakutenOrder2() {
        rakutenService.autoSendRakutenOrder2();
        yahooService.autoSendYahooOrder();
    }

    @Scheduled(fixedDelay = 100000 * 60 * 1000)
    private void updateOrderOutChehckStatus1() {
//        outputService.countShipFee();
//
//        System.out.println();
//        List<OrderOutputProductDo> productDoList = new ArrayList<>();
//        OrderOutputProductDo o1 = new OrderOutputProductDo();
//        o1.setProductId(1L);
//        o1.setCount(1);
//        OrderOutputProductDo o2 = new OrderOutputProductDo();
//        o2.setProductId(2L);
//        o2.setCount(2);
//        OrderOutputProductDo o3 = new OrderOutputProductDo();
//        o3.setProductId(3L);
//        o3.setCount(1);
//        productDoList.add(o1);
//        productDoList.add(o2);
//        productDoList.add(o3);
//
//        double[] size = mShipPriceService.getMulitSkuSize(productDoList);
//        System.out.println(size[0] + ":" + size[1] + ":" + size[2] + ":" + size[3] + ":");
//        outputService.getPackageSizeInfoCount(productDoList, new double[]{}, 5L, 10L);
    }


}